Skip to content

fix: don't write the default event_time back onto the caller's event - #17

Merged
drkjc merged 1 commit into
spreedly:mainfrom
Mohith26:fix/event-time-not-written-back
Nov 11, 2026
Merged

drkjc merged 1 commit into
spreedly:mainfrom
Mohith26:fix/event-time-not-written-back

Conversation

@Mohith26

@Mohith26 Mohith26 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

event() fills in event_time when the caller left it empty, but it does that by assigning to the caller's TrackEvent. If the same event object is sent again later, it already has a timestamp, so the second call goes out with the first call's time.

event = TrackEvent(type="login", data={"userId": "user123"})
composer.event(event, session_id="sess123")   # eventTime = now
# ...a minute later
composer.event(event, session_id="sess123")   # eventTime is still the first call's time

This change computes the default for the request only and leaves the caller's object alone, the same way __init__ copies the config instead of mutating it. A caller-provided event_time is still sent unchanged.

Tests: added test_event_does_not_write_default_time_back_to_event (fails on main with [1000000, 1000000] == [1000000, 2000000], passes with the fix) and test_event_keeps_caller_event_time. pytest (163 passed), ruff format --check composer tests, ruff check composer tests and mypy composer pass locally on Python 3.12.

The Node, Ruby and Go server SDKs set the default the same way, so they may want the same change. I used AI assistance while working on this and reviewed and tested the change myself.

event() set event.event_time when it was empty, so an event object reused
for a later call was sent with the first call's timestamp. Use the default
for the request only.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the timestamp-handling change.

No open issues 🎉

What changed in this PR

Fixes timestamp handling in the Python SDK’s Composer.event() so reusing a TrackEvent generates a fresh default timestamp without modifying the caller’s object.

Changes:

  • Computes the default timestamp locally for each request.
  • Adds regression tests for reused events and preservation of caller-provided timestamps.
File Description
tests/​test_composer.py Adds tests for fresh default timestamps and explicit timestamp preservation.
composer/​composer.py Sends a request-local timestamp instead of assigning it to the caller’s event.

Review effort: Balanced

@drkjc drkjc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, the fix and tests are clear. Thanks for the contribution, and the note about the other sdks!

@drkjc
drkjc merged commit 8f3e437 into spreedly:main Nov 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants